class Solution {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> tem = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        boolean[] isuse = new boolean[nums.length];
        dfs(0,nums,isuse);
        return res;
    }

    private void dfs(int cur,int[] nums,boolean[] isuse) {
            if(cur == nums.length) {
                res.add(new ArrayList<>(tem));
                return;
            }
            
        //在数组中找到一个未选择的数
        for(int i = 0;i<isuse.length;i++) {
            if(!isuse[i]) {
                tem.add(nums[i]);
                isuse[i] = true;
                dfs(cur+1,nums,isuse);
                tem.remove(tem.size()-1);
                isuse[i] = false;
            }
        }
        

    }
}